#include <iostream>
#include <unistd.h>
#include <signal.h>
#include <functional>

void handlerSig(int signum)
{
    std::cout << "SIGALRM received: " << signum << std::endl;
    signal(SIGINT, SIG_DFL); // 重新设置信号处理函数为默认
    std::cout << "Re-setting signal handler to default" << std::endl;

}

int main()
{
    // 自定义捕捉
    // signal(SIGINT, [](int signum) {std::cout << "SIGINT received: " << signum << std::endl;});
    signal(SIGINT, handlerSig);
    // signal(SIGINT, SIG_IGN); // 忽略信号

    while (true) 
    {
        sleep(1);
        std::cout << "Hello, world!" << std::endl;
    }   

    return 0;
}
